package org.example.sportdemo.service;

import org.example.sportdemo.entity.Ground;
import org.example.sportdemo.entity.Product;
import org.example.sportdemo.mapper.GroundMapper;
import org.example.sportdemo.mapper.ProductMapper;
import org.example.sportdemo.utils.PageUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.Map;

@Service
public class ProductService {

    @Autowired
    private ProductMapper productMapper;

    public List<Product> selectAll(){
        return productMapper.selectAll();
    }

    public PageUtils queryPage(Map<String, Object> params) {
        //总数据
        List<Product> groundList = productMapper.selectAll();
        //总条数
        Integer totalCount = productMapper.selectCount();
        //当前页
        Integer currPage = Integer.valueOf((String) params.get("currPage"));
        //每页条数
        Integer pageSize = Integer.valueOf((String) params.get("pageSize"));
        return new PageUtils(totalCount,(Integer) pageSize,currPage,groundList);
    }

    public void addProduct(Product product) {

        Date date = new Date();
        product.setCreate_time(date);
        productMapper.addProduct(product);

    }

    public Product selectById(Integer id) {
        return productMapper.selectById(id);
    }

    public void updateProduct(Product product) {
        productMapper.updateProduct(product);
    }

    public void deleteByIds(Integer[] ids) {
        productMapper.deleteByIds(ids);
    }

    public List<Product> selectForHot() {
        return productMapper.selectForHot();
    }
}
